#ifndef __COMPLEX__
#define __COMPLEX__

class complex
{
public:
    complex(double r=0, double i =0.): re(r), im(i){}
    complex& operator +=(const complex &);
    double real() const { return re; }
    double imag() const { return im; }

private:
    double re, im;
    friend complex& __doapl(complex*, const complex&);
};

inline complex& __doapl(complex* ths, const complex& r){
    ths->re += r.re;
    ths->im += r.im;
    return *ths;
}
//包括了隐藏的this
inline complex& complex::operator +=(const complex& r){
    return __doapl(this, r);
}

inline double
imag (const complex& x)
{
  return x.imag ();
}

inline double
real (const complex& x)
{
  return x.real ();
}

//这里一定不能加引用
complex operator +(const complex& x, const complex& y){
    //创建新的对象
    //以类的名称+小括号的形式
    return complex(real(x) + real(y),
                   imag(x) + imag(y));
}


#endif